package com.company.controller;

import com.company.CompanyException;
import com.company.model.Feedback;
import com.company.model.request.FeedbackRequest;
import com.company.model.result.BaseResult;
import com.company.service.IFeedbackService;
import com.company.utils.RequestUtil;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by tu on 2017/6/1.
 */
@RestController
@RequestMapping(value = "/feedbacks")
public class FeedbackController {

  @Autowired
  IFeedbackService service;

  @RequestMapping(method = RequestMethod.POST)
  public BaseResult add(@RequestBody FeedbackRequest dto, HttpServletRequest request)
      throws CompanyException {
    String userAgent = RequestUtil.getUserAgent(request);
    BaseResult result = new BaseResult();
    Feedback info = service.add(dto, userAgent);
    result.setData(info);
    return result;
  }
}
